<template>
    <div>
      <!-- 面包屑导航条 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/toOneList' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>发票管理</el-breadcrumb-item>
        <el-breadcrumb-item>发票审核</el-breadcrumb-item>
      </el-breadcrumb>
      <!--标题-->
      <el-row class="box2">
        <h1 class="title">发票审核界面</h1>
      </el-row>
      <!--中间间隔-->
      <el-row class="box"></el-row>
      <!--添加界面-->
      <el-card class="box-card">
        <p style="color: black;font-size: 25px">可发票总金额(不含税):{{price}}元</p>
        <el-form :model="billForm" ref="billForm" :rules="rules">
          <!------------------------------------------------------------------------->
          <el-row type="flex" class="row-bg" justify="space-around">
            <el-col :span="9">
              <el-form-item label="发票抬头：" label-width="100px">
                <el-input :disabled="this.ckk==0 || this.ckk==1" v-model="billForm.invoiceTitle" style="width: 220px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="税号：" label-width="100px">
                <el-input :disabled="this.ckk==0 || this.ckk==1" v-model="billForm.invoiceNum" style="width: 220px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!------------------------------------------------------------------------->
          <el-row type="flex" class="row-bg" justify="space-around">
            <el-col :span="9">
              <el-form-item label="发票类型：" label-width="100px">
                <el-select :disabled="this.ckk==0 || this.ckk==1" v-model="billForm.invoiceType" clearable placeholder="请选择">
                  <el-option  label="增值税普通发票" :value="0"></el-option>
                  <el-option label="增值税专用" :value="1"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="税率：" label-width="100px">
                <el-input :disabled="this.ckk==0 || this.ckk==1" v-model="billForm.taxRate" style="width: 220px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!------------------------------------------------------------------------->
          <el-row type="flex" class="row-bg" justify="space-around">
            <el-col :span="9">
              <el-form-item label="开票金额：" label-width="100px">
                <el-input :disabled="this.ckk==0" @blur="ckamount" v-model="billForm.amount" style="width: 220px"></el-input>
                <span v-if="inck==1">{{msg}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="发票内容；" label-width="100px">
                <el-input :disabled="this.ckk==0" v-model="billForm.content" style="width: 220px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!------------------------------------------------------------------------->
          <el-row type="flex" class="row-bg" justify="space-around">
            <el-col :span="9">
              <el-form-item label="收件人：" label-width="100px">
                <el-input :disabled="this.ckk==0" v-model="billForm.receiver" style="width: 220px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="联系电话：" label-width="100px">
                <el-input :disabled="this.ckk==0" v-model="billForm.tel" style="width: 220px"  ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!------------------------------------------------------------------------->
          <el-row type="flex" class="row-bg" justify="space-around">
            <el-col :span="9">
              <el-form-item label="收货地址：" label-width="100px">
                <el-input :disabled="this.ckk==0" v-model="billForm.revAddress" style="width: 220px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="物流公司：" label-width="100px">
                <el-input :disabled="this.ckk==0 " v-model="billForm.logistics_cym" style="width: 220px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!------------------------------------------------------------------------->
          <el-row type="flex" class="row-bg" justify="space-around">
            <el-col :span="9">
              <el-form-item label="快递单号：" label-width="100px">
                <el-input :disabled="this.ckk==0" v-model="billForm.logistics_code" style="width: 220px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="9">
            </el-col>
          </el-row>
          <!------------------------------------------------------------------------->
        </el-form>
          <el-button v-if="this.ckk==1" type="success" :disabled="flog" @click="updateAndSave(2)">通过</el-button>
          <el-button v-if="this.ckk==1" type="info"   :disabled="flog" @click="updateAndSave(3)">驳回</el-button>
        <el-button v-if="this.ckk==1" type="info"  @click="goback()">返回</el-button>
      </el-card>
    </div>
</template>

<script>
    export default {
        name: "bilAdd",
      data(){
        return{
          flog:false,
          rules: {
            amount: [
              {max:this.priceIt, message: '超出金额', trigger: 'blur' }
            ]
          },
          billForm:{
            priceIt:0,
            price:0,
            amount:null,
          },
          us:{
            id:'',
            userName:'',
            fullName:'',
          },//获取会话的用户对象
          ckk:'',
          priceIt:0,
          price:0,
          inck:0,
          msg:'',
        }
      },
      methods: {
        goback() {
          this.$router.push('/bill')
        },
        ckamount() {
          debugger
          let a = this.billForm.amount;
          let b = this.price;
          if (a > b) {
            this.$message({
              message: '已超过最大可开票金额，请重新输入',
              type: "warning"
            })
            this.flog=true;
          }else{
            this.flog=false;
          }
        },
        updateAndSave(up) {//通过或者驳回
          debugger
          let name = this.us.fullName;
          let userid = this.us.id;
          let bill = this.billForm
          this.$http.post("/bil/updateAndSave/" + up + "/" + name + "/" + userid, bill).then((res) => {
            if (res.data.success) {
              this.$message({
                message: res.data.message,
                type: "success"
              })
              this.$router.push('/bill')
            } else {
              this.$message.error(res.data.message);
            }
          });
        },
        getBill(id) {//回显
          this.$http.post("/bil/getById/" + id).then((res) => {
            if (res.data.success) {
              this.$message.success(res.data.message);
              debugger
              this.billForm = res.data.result.invoice;
              this.priceIt = res.data.result.piOrder.priceIt;
              this.price = res.data.result.piOrder.price;
            } else {
              this.$message.error(res.data.message);
            }
          })
        }
      },
      mounted() {
          debugger
        this.us=JSON.parse(sessionStorage.getItem("user"));
        this.ckk=this.$route.query.ck;
        let id=this.$route.query.id;
        this.getBill(id)
      }
    }
</script>

<style scoped>
  .row-bg {/*添加界面布局的样式*/
    padding: 10px 0;
  }
  .box2{/*添加界面的样式*/
    height: 80px;
    border-radius: 40px;
  }
  .box-card{/*列表的样式*/
    border-radius: 30px;
  }
  .box3{/*回显数据*/
    height: 100px;
  }
  .title{
    line-height:2.3px;
    text-align: center;
  }
</style>
